# Makefile for JamesM's kernel tutorials.
# The C and C++ rules are already setup by default.
# The only one that needs changing is the assembler 
# rule, as we use nasm instead of GNU as.
API_DIR=./api
API_HEADERS_DIR=$(API_DIR)/headers
SOURCES=boot.o main.o $(API_DIR)/io.o $(API_DIR)/string.o $(API_DIR)/ctype.o memory/gdtFlush.o memory/gdt.o memory/kheap.o memory/paging.o interrupts/idt.o interrupts/isr.o interrupts/idt_asm.o interrupts/isr_asm.o interrupts/pic.o interrupts/irq.o interrupts/irq_asm.o adt/ordered_array.o tools/common.o multitasking/timer.o io/keyboard.o api/errors.o adt/heap.o memory/process.o multitasking/task.o multitasking/task_asm.o adt/queue.o adt/linked_list.o fileSystem/initialization.o fileSystem/fat16.o fileSystem/partitioning.o fileSystem/diskIO.o interface/shell.o interface/user_progs.o multitasking/process_killer.o
CFLAGS=-Wall -nostdlib -nostdinc -fno-builtin -fno-stack-protector -march=pentium
LDFLAGS=-Tlink.ld
ASFLAGS=-felf
OUTNAME=kernel

all: link

clean:
	find -name '*.o' -delete

link: $(SOURCES)
	ld $(LDFLAGS) -o $(OUTNAME) $(SOURCES)
#.suffixes: .s -> .asm
.s.o:
	nasm $(ASFLAGS) $<

boot.o: main.o
main.o: $(API_DIR)/io.o $(API_HEADERS_DIR)/colours.h $(API_HEADERS_DIR)/dataTypes.h memory/gdt.o main.c memory/gdtFlush.o memory/gdt.o memory/kheap.o memory/paging.o
(API_DIR)/io.o: (API_HEADERS_DIR)/io.h $(API_HEADERS_DIR)/colours.h $(API_HEADERS_DIR)/dataTypes.h
memory/gdt.o: memory/headers/gdt.h
memory/kheap.o: memory/headers/kheap.h
memory/paging.o: memory/headers/paging.h $(API_DIR)/string.o
$(API_DIR)/string.o: $(API_HEADERS_DIR)/string.h $(API_DIR)/ctype.o
adt/ordered_array.o: adt/headers/ordered_array.h
tools/common.o: tools/headers/common.h
